package com.dayuanit.dy17.atm.atmbackoffice.controller;

import com.dayuanit.dy17.atm.atmbackoffice.dto.ResponseDTO;
import com.dayuanit.dy17.atm.atmbackoffice.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @RequestMapping(value = "/role/addRole", method = RequestMethod.POST)
    public ResponseDTO addRole(String roleKey, String roleValue) {
        roleService.createRole(roleKey, roleValue);
        return ResponseDTO.success();
    }

    @PostMapping("/role/addUserRefRole")
    public ResponseDTO addUserRefRole(String username, @RequestParam("roleIds[]") Long[] roleIds) {
        for (Long roleId : roleIds) {
            System.out.println(">>>" + roleId);
        }

        roleService.addUserRefRole(username, roleIds);
        return ResponseDTO.success();
    }

    @RequestMapping("/role/loadAllRole")
    public ResponseDTO loadAllRole() {
        return ResponseDTO.success(roleService.loadRoles());
    }
}
